﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using GS.Utilies;
using GS.DataConnection;

namespace GS.CMS.Entities
{
    public class Users
    {
        #region "Declare Variables"
        int _UserID, _DistrictID, _ProvinceID, _CountryID,_RoleID;
        string _Email, _FirstName, _LastName, _Password, _ACLs, _Address, _Phone, _Picture, _RoleName, _AccountName
            , _Licence, _TempPassword, _GroupName, _MobilePhone, _Fax, _WorkPhone, _HomePhone, _AboutMe;
        bool _IsDisable, _Gender;
        decimal _Salary;
        DateTime _CreatedDate, _LastLogin, _Birthday;
        Guid _SessionID, _ActiveKey;
        #endregion

        #region "Properties"
        public Guid SessionID
        {
            get { return _SessionID; }
            set { _SessionID = value; }
        }
        public DateTime LastLogin
        {
            get { return _LastLogin; }
            set { _LastLogin = value; }
        }
        public DateTime CreatedDate
        {
            get { return _CreatedDate; }
            set { _CreatedDate = value; }
        }
        public DateTime Birthday
        {
            get { return _Birthday; }
            set { _Birthday = value; }
        }
        public int RoleID
        {
            get { return _RoleID; }
            set { _RoleID = value; }
        }
        public string AccountName
        {
            get { return _AccountName; }
            set { _AccountName = value; }
        }
        public string GroupName
        {
            get { return _GroupName; }
            set { _GroupName = value; }
        }
        public string RoleName
        {
            get { return _RoleName; }
            set { _RoleName = value; }
        }
        public string Licence
        {
            get { return _Licence; }
            set { _Licence = value; }
        }
        public string Picture
        {
            get { return _Picture; }
            set { _Picture = value; }
        }
        public string Password
        {
            get { return _Password; }
            set { _Password = value; }
        }
        public string LastName
        {
            get { return _LastName; }
            set { _LastName = value; }
        }
        public string FirstName
        {
            get { return _FirstName; }
            set { _FirstName = value; }
        }
        public string Email
        {
            get { return _Email; }
            set { _Email = value; }
        }
        public int UserID
        {
            get { return _UserID; }
            set { _UserID = value; }
        }
        public bool IsDisable
        {
            get { return _IsDisable; }
            set { _IsDisable = value; }
        }
        public bool Gender
        {
            get { return _Gender; }
            set { _Gender = value; }
        }
        public string ACLs
        {
            get { return _ACLs; }
            set { _ACLs = value; }
        }
        public string MobilePhone
        {
            get { return _MobilePhone; }
            set { _MobilePhone = value; }
        }
        public string WorkPhone
        {
            get { return _WorkPhone; }
            set { _WorkPhone = value; }
        }
        public string HomePhone
        {
            get { return _HomePhone; }
            set { _HomePhone = value; }
        }
        public string Fax
        {
            get { return _Fax; }
            set { _Fax = value; }
        }
        public string Address
        {
            get { return _Address; }
            set { _Address = value; }
        }
        public int DistrictID
        {
            get { return _DistrictID; }
            set { _DistrictID = value; }
        }
        public int ProvinceID
        {
            get { return _ProvinceID; }
            set { _ProvinceID = value; }
        }
        public int CountryID
        {
            get { return _CountryID; }
            set { _CountryID = value; }
        }
        public Guid ActiveKey
        {
            get { return _ActiveKey; }
            set { _ActiveKey = value; }
        }
        public string TempPassword
        {
            get { return _TempPassword; }
            set { _TempPassword = value; }
        }
        #endregion

        #region "Public Method"
        //public DataSet getUserList(int _Pgnum, string _KeySearch)
        //{
        //    System.Collections.Hashtable ht = new System.Collections.Hashtable();
        //    ht.Add("@Pgnum", _Pgnum);
        //    ht.Add("@n_KeySearch", _KeySearch);
        //    return dataConnection.sqlProvider.GetDataSet("w_user_list", ht);
        //}
        //public DataTable GetListRoles()
        //{
        //    return dataConnection.sqlProvider.GetTable("w_roles_sel", "dtRole");
        //}
        //public int UpdateUser()
        //{
        //    System.Collections.Hashtable ht = new System.Collections.Hashtable();
        //    ht.Add("@UserID", UserID);
        //    ht.Add("@EmailLogin ", Email);
        //    ht.Add("@Password", Encode.EncodePassword(Password));
        //    ht.Add("@n_FirstName", FirstName);
        //    ht.Add("@n_LastName", LastName);
        //    ht.Add("@Role", RoleID);
        //    ht.Add("@n_Address", Address);
        //    ht.Add("@DistrictID", DistrictID);
        //    ht.Add("@CountryID", CountryID);
        //    ht.Add("@Phone", Phone);
        //    ht.Add("@ProvinceID", ProvinceID);
        //    ht.Add("@ImgPath", ImgPath);
        //    ht.Add("@Salary", Salary);
        //    ht.Add("@Birthday", Birthday);
        //    ht.Add("@EnFullName", EnfullName);
        //    ht.Add("@n_Licence", Licence);
        //    ht.Add("@Gender", Sex);
        //    return int.Parse(sqlProvider.GetTable("w_user_update", "dtuser", ht).Rows[0][0].ToString());
        //}
        //public int UpdateClient()
        //{
        //    System.Collections.Hashtable ht = new System.Collections.Hashtable();
        //    ht.Add("@PatientID", UserID);
        //    ht.Add("@Email", Email);
        //    ht.Add("@n_FullName", FirstName);
        //    ht.Add("@Phone", Phone);
        //    ht.Add("@Birthday", Birthday);
        //    ht.Add("@n_Address", Address);
        //    ht.Add("@DistrictID", DistrictID);
        //    ht.Add("@CountryID", CountryID);
        //    ht.Add("@ProvinceID", ProvinceID);
        //    ht.Add("@Gender", Sex);
        //    ht.Add("@EnFullName", EnfullName);
        //    ht.Add("@PatientType", PatientType);
        //    ht.Add("@QtyExamination", QtyExamination);
        //    ht.Add("@n_DoctorName", DoctorName);
        //    return int.Parse(sqlProvider.ExecuteScalar("w_patient_update", ht).ToString());
        //}
        //public int UpdateRoles(string Description, string Name)
        //{
        //    System.Collections.Hashtable ht = new System.Collections.Hashtable();
        //    ht.Add("@RoleID", RoleID);
        //    ht.Add("@n_Description", Description);
        //    ht.Add("@n_Name ", Name);
        //    return sqlProvider.ExecuteSQL("w_roles_update", ht);
        //}
        public DataTable Login()
        {
            try
            {
                System.Collections.Hashtable ht = new System.Collections.Hashtable();
                ht.Add("@Email", Email);
                ht.Add("@Password", Encode.EncodePassword(Password));
                return SqlProvider.GetTable("pro_users_login", "dtUser", ht);
            }
            catch (Exception ex)
            {
                TrackingError.AddTrackingError("User: sanghv - Function: Login - Class: Users", ex.Message);
                return null;
            }
        }
        //public DataSet GetUserInfo(int UserID)
        //{
        //    System.Collections.Hashtable ht = new System.Collections.Hashtable();
        //    ht.Add("@User_ID", UserID);
        //    return sqlProvider.GetDataSet("w_users_get_info", ht);
        //}
        //public DataSet GetClientInfo(int UserID)
        //{
        //    System.Collections.Hashtable ht = new System.Collections.Hashtable();
        //    ht.Add("@Patient_ID", UserID);
        //    return sqlProvider.GetDataSet("w_patients_get_info", "Patient", ht);
        //}
        //public DataTable GetUserID(int UserID)
        //{
        //    System.Collections.Hashtable ht = new System.Collections.Hashtable();
        //    ht.Add("@UserID", UserID);
        //    return sqlProvider.GetTable("w_users_get_id", "dtUser", ht);
        //}
        //public int DeleteUsers(string UserIDs)
        //{
        //    System.Collections.Hashtable ht = new System.Collections.Hashtable();
        //    ht.Add("@UserIDs", UserIDs);
        //    return sqlProvider.ExecuteSQL("w_user_delete", ht);
        //}
        //public int DeleteRoles(string RoleIDs)
        //{
        //    System.Collections.Hashtable ht = new System.Collections.Hashtable();
        //    ht.Add("@RoleID", RoleIDs);
        //    return sqlProvider.ExecuteSQL("w_roles_delete", ht);
        //}
        //public int ChangePassword(int UserID)
        //{
        //    System.Collections.Hashtable ht = new System.Collections.Hashtable();
        //    ht.Add("@UserID", UserID);
        //    ht.Add("@OldPass", Utilies.Encode.EncodePassword(OldPass));
        //    ht.Add("@NewPass", Utilies.Encode.EncodePassword(Password));
        //    return int.Parse(sqlProvider.ExecuteScalar("w_users_changepassword", ht).ToString());

        //}
        //public DataTable GetRoleByID(byte RoleID)
        //{
        //    System.Collections.Hashtable ht = new System.Collections.Hashtable();
        //    ht.Add("@RoleID", RoleID);
        //    return sqlProvider.GetTable("w_roles_sel_id", "dtRoles", ht);
        //}
        //public DataTable UpdatePassword()
        //{
        //    System.Collections.Hashtable ht = new System.Collections.Hashtable();
        //    ht.Add("@Email", Email);
        //    ht.Add("@Password", Password);
        //    return sqlProvider.GetTable("w_update_pass", "User", ht);
        //}
        public int UpdatePasswordTemp()
        {
            System.Collections.Hashtable ht = new System.Collections.Hashtable();
            ht.Add("@Email", Email);
            ht.Add("@Password", Encode.EncodePassword(TempPassword));
            ht.Add("@ActiveKey", ActiveKey);
            return SqlProvider.ExecuteSQL("pro_user_update_passtemp", ht);
        }
        public DataTable GetUserByEmail()
        {
            System.Collections.Hashtable ht = new System.Collections.Hashtable();
            ht.Add("@Email", Email);
            return SqlProvider.GetTable("pro_users_get_email", "User", ht);
        }
        //public DataTable ActiveUserByActivekey()
        //{
        //    System.Collections.Hashtable ht = new System.Collections.Hashtable();
        //    ht.Add("@ActiveKey", ActiveKey);
        //    return sqlProvider.GetTable("w_active_by_activekey", "User", ht);
        //}
        //public int UpdateActiKey()
        //{
        //    System.Collections.Hashtable ht = new System.Collections.Hashtable();
        //    ht.Add("@ActiveKey", ActiveKey);
        //    return sqlProvider.ExecuteSQL("w_update_by_activekey", ht);
        //}
        #endregion

        #region "Constructor"
        public Users()
        {
            /* Huynh Van Sang
             * Date :02/04/2009
             */
        }
        #endregion
    }
}
